package com.sping_boot3.spirng_boot3.config;

import com.sping_boot3.spirng_boot3.juc.Alternate_Lock;
import com.sping_boot3.spirng_boot3.juc.Alternate_synchronized;
import com.sping_boot3.spirng_boot3.juc.线程定制化化通信;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnSingleCandidate;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;

import java.lang.reflect.Type;
import java.util.concurrent.locks.ReentrantLock;

@Configuration
public class RedisConfig {
    @Bean
    public RedisTemplate<String, Object> redisTemplate(LettuceConnectionFactory lettuceConnectionFactory)
    {
        RedisTemplate<String,Object> redisTemplate = new RedisTemplate<>();
        redisTemplate.setConnectionFactory(lettuceConnectionFactory);
        //设置key序列化方式string
        redisTemplate.setKeySerializer(new StringRedisSerializer());
        //设置value的序列化方式json
        redisTemplate.setValueSerializer(new GenericJackson2JsonRedisSerializer());

        redisTemplate.setHashKeySerializer(new StringRedisSerializer());
        redisTemplate.setHashValueSerializer(new GenericJackson2JsonRedisSerializer());

        redisTemplate.afterPropertiesSet();

        return redisTemplate;
    }
    @Bean
    public ReentrantLock reentrantLock(){
        return new ReentrantLock();
    }
    @Bean
    public Alternate_synchronized alternate_synchronized(){
        return new Alternate_synchronized();
    }
    @Bean
    public Alternate_Lock alternate_lock(){
        return new Alternate_Lock();
    }
    @Bean
    public 线程定制化化通信 线程定制化化通信(){
       return new 线程定制化化通信();
    }
}
